<template>
  <div >
    <enum_chb :param="{}" v-if="enumField.enum_val&&enumField.fval!==undefined" :field="enumField" @setVo='setEnum' ></enum_chb>
    <div class="field">
      <label for="">保存配置</label>
      <button class="ui button" @click.stop.prevent="saveConf">保存配置</button>
    </div>
  </div>

  <!--<enum_many :param="{}" v-if="enumField.enum_val&&enumField.fval!==undefined" :field="enumField" type="checkbox" @setVo='setEnum' ></enum_many>-->
</template>

<script type="text/ecmascript-6">
  import tool from 'src/util/tool';
  import util from '_util/index';
  import logic from '_logic';

  import enum_chb from 'components/field/enum_chb';
  import enum_many from 'components/field/enum_many';

  export default {
    data() {
      return {
        hide_keys: '',
        notHave: false,

        enumField:{
          name:'hide_keys',
          title:'',
          enum_val:null
        },
      }
    },
    components: {enum_chb,enum_many},
    methods: {
      saveConf(){
        let op = 'upListHide';
        let url = tool.getApi(this,'Post', op);
        let vo = {
          list_hide_keys: this.hide_keys,
          model:this.ctl
        };
        util.http.SR(this, url, vo, '保存配置成功!',()=> {
        });
      },
      getAllFields(){
        let vo = util.store.get(this, 'editVoModal');
        this.$set(this.enumField, 'enum_val', vo.list_fileds);

        let hide_fileds=util.store.get(this,  `hideFields.${this.ctl}`, 'list')||'';
        if(hide_fileds) {
          hide_fileds=hide_fileds.join('|')
        }
        this.$set(this.enumField, 'fval', hide_fileds);

      },
      getProductAttr(){
        let url = tool.getApi(this, 'Editget', 'getProductAttrs');
        let param =  util.store.get(this, 'editVoModal');
        util.getDataCom(this, url, param, (rs) => {
          rs=rs.attr_names;
          if(rs&&Object.keys(rs).length>0) {
            let tmp = [];
            for(let ind in rs) {
              tmp.push({
                id: ind,
                title: rs[ind]
              })
            }
            this.$set(this.enumField, 'enum_val', tmp);
            this.$set(this.enumField, 'fval', '');
          }else{
//            util.showMsg(this, 'info', '该商品的规格都已经绑定到该仓库！')
            this.notHave = true;
          }

        })
      },
      setEnum(fname,val) {
//
        val = val.replace(/\|/g, ',');
        this[fname] = val;
        this.$emit('setVo', this.field.name,val );
      },
    },
    watch: {
    },
    computed: {
      ctl(){
        return this.$route.query.ctl;
      }
    },
    props: ['field'],
    created() {
//      this.getProductAttr();
      this.getAllFields();
    },
    mounted() {
    }
  };
</script>

<style scoped>
</style>
